package com.mofeng.myshop.domain.dto;

import com.mofeng.myshop.domain.dto.base.BaseDto;
import com.mofeng.myshop.domain.po.CommodityCategory;
import com.mofeng.myshop.until.MyUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class CommodityCategoryDto extends BaseDto {
    @Schema(description = "项目ID")
    private String projectId;

    @Schema(description = "父级目录ID")
    private String parentId;

    @Schema(description = "图片路径")
    private String image;

    @Schema(description = "小图标")
    private String iconImage;

    @Schema(description = "按组发货，一组多少个")
    private Integer groupNumber;

    @Schema(description = "等级限制")
    private Integer levelTop;

    @Schema(description = "单位")
    private String unit;

    @Schema(description = "有无蓝图 0有 1无")
    private String hasPic;

    @Schema(description = "有无质量 0有 1无")
    private String hasMultiplier;

    @Schema(description = "虚拟删除状态， 0 存在  1删除")
    private String delete;

    @Schema(description= "代码前缀(功能码)")
    private String codePrefix;

    @Schema(description = "是否展示 0 展示 1 不展示 注意，不展示意思是前端将不会显示此分类")
    private String show;

    @Schema(description = "是否打开 0打开 1 关闭  注意，关闭意思是无法访问，但会显示禁止访问提示")
    private String open;

    public CommodityCategory toCommodityCategory() {
        CommodityCategory commodityCategory = new CommodityCategory();
        toBaseEntity(commodityCategory);
        if (this.projectId != null) {
            commodityCategory.setProjectId(MyUtil.NumberUtil.asLong(this.projectId));
        }

        if (this.parentId != null) {
            commodityCategory.setParentId(MyUtil.NumberUtil.asLong(this.parentId));
        }
        if (this.image != null) {
            commodityCategory.setImage(this.image);
        }
        if (this.iconImage != null) {
            commodityCategory.setIconImage(this.iconImage);
        }
        if (this.codePrefix != null) {
            commodityCategory.setCodePrefix(this.codePrefix);
        }
        if (this.groupNumber != null) {
            if (MyUtil.NumberUtil.isNum(this.groupNumber + "")) {
                commodityCategory.setGroupNumber(this.groupNumber);
            }
        }
        if (this.hasPic != null) {
            commodityCategory.setHasPic(this.hasPic);
        }
        if (this.hasMultiplier != null) {
            commodityCategory.setHasMultiplier(this.hasMultiplier);
        }

        if (this.unit != null) {
            commodityCategory.setUnit(this.unit);
        }

        if (this.delete != null) {
            commodityCategory.setDelete(this.delete);
        }
        if (this.show != null) {
            commodityCategory.setShow(this.show);
        }
        if (this.open != null) {
            commodityCategory.setOpen(this.open);
        }
        return commodityCategory;
    }
}
